function a(ele){return document.querySelector(ele)}
function c(ele){return document.createElement(ele)}

//ajax_get
function ajax_get(url){
    return new Promise((resolve,reject)=>{
        let xhr=new XMLHttpRequest()
        xhr.open("get",url,true)
        xhr.send()
        xhr.onreadystatechange=()=>{
            if(xhr.readyState === 4 && xhr.status === 200){
                resolve(xhr.responseText)
            }
        }
    })
}
//ajax_post
function ajax_post(url,str){
    return new Promise((resolve,reject)=>{
        let xhr=new XMLHttpRequest()
        xhr.open("post",url,true)
        xhr.setRequestHeader('content-type','application/x-www-form-urlencoded')
        xhr.send(str)
        xhr.onreadystatechange=()=>{
            if(xhr.readyState === 4 && xhr.status === 200){
                resolve(xhr.responseText)
            }
        }
    })
}

$("#btn1").on("click",function(){
    let str="username="+$("#username").val()+"&pwd="+$("#pwd").val()+"&phone="+$("#phone").val()
    ajax_post("./register_post.php",str).then(result=>{
        console.log(result)
    })
    a("#form").reset()
})
$("#btn2").on("click",function(){
    let str="id=1"+"&pwd="+$("#pwd").val()+"&phone="+$("#phone").val()
    ajax_post("./register_update.php",str).then(result=>{
        console.log(result)
    })
    a("#form").reset()
})